// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

public sealed partial class PercolateQuery
{
	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("boost")]
	public float? Boost { get; set; }

	/// <summary>
	/// <para>
	/// The source of the document being percolated.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("document")]
	public object? Document { get; set; }

	/// <summary>
	/// <para>
	/// An array of sources of the documents being percolated.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("documents")]
	public ICollection<object>? Documents { get; set; }

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Field Field { get; set; }

	/// <summary>
	/// <para>
	/// The ID of a stored document to percolate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("id")]
	public Elastic.Clients.Elasticsearch.Id? Id { get; set; }

	/// <summary>
	/// <para>
	/// The index of a stored document to percolate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index")]
	public Elastic.Clients.Elasticsearch.IndexName? Index { get; set; }

	/// <summary>
	/// <para>
	/// The suffix used for the <c>_percolator_document_slot</c> field when multiple <c>percolate</c> queries are specified.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("name")]
	public string? Name { get; set; }

	/// <summary>
	/// <para>
	/// Preference used to fetch document to percolate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("preference")]
	public string? Preference { get; set; }
	[JsonInclude, JsonPropertyName("_name")]
	public string? QueryName { get; set; }

	/// <summary>
	/// <para>
	/// Routing used to fetch document to percolate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("routing")]
	public Elastic.Clients.Elasticsearch.Routing? Routing { get; set; }

	/// <summary>
	/// <para>
	/// The expected version of a stored document to percolate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("version")]
	public long? Version { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.Query(PercolateQuery percolateQuery) => Elastic.Clients.Elasticsearch.QueryDsl.Query.Percolate(percolateQuery);
}

public sealed partial class PercolateQueryDescriptor<TDocument> : SerializableDescriptor<PercolateQueryDescriptor<TDocument>>
{
	internal PercolateQueryDescriptor(Action<PercolateQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public PercolateQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private object? DocumentValue { get; set; }
	private ICollection<object>? DocumentsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Id? IdValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; }
	private string? NameValue { get; set; }
	private string? PreferenceValue { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; }
	private long? VersionValue { get; set; }

	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The source of the document being percolated.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Document(object? document)
	{
		DocumentValue = document;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An array of sources of the documents being percolated.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Documents(ICollection<object>? documents)
	{
		DocumentsValue = documents;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The ID of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id? id)
	{
		IdValue = id;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The index of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Index(Elastic.Clients.Elasticsearch.IndexName? index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The suffix used for the <c>_percolator_document_slot</c> field when multiple <c>percolate</c> queries are specified.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Name(string? name)
	{
		NameValue = name;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Preference used to fetch document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Preference(string? preference)
	{
		PreferenceValue = preference;
		return Self;
	}

	public PercolateQueryDescriptor<TDocument> QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Routing used to fetch document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Routing(Elastic.Clients.Elasticsearch.Routing? routing)
	{
		RoutingValue = routing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The expected version of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor<TDocument> Version(long? version)
	{
		VersionValue = version;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (DocumentValue is not null)
		{
			writer.WritePropertyName("document");
			JsonSerializer.Serialize(writer, DocumentValue, options);
		}

		if (DocumentsValue is not null)
		{
			writer.WritePropertyName("documents");
			JsonSerializer.Serialize(writer, DocumentsValue, options);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (IdValue is not null)
		{
			writer.WritePropertyName("id");
			JsonSerializer.Serialize(writer, IdValue, options);
		}

		if (IndexValue is not null)
		{
			writer.WritePropertyName("index");
			JsonSerializer.Serialize(writer, IndexValue, options);
		}

		if (!string.IsNullOrEmpty(NameValue))
		{
			writer.WritePropertyName("name");
			writer.WriteStringValue(NameValue);
		}

		if (!string.IsNullOrEmpty(PreferenceValue))
		{
			writer.WritePropertyName("preference");
			writer.WriteStringValue(PreferenceValue);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (RoutingValue is not null)
		{
			writer.WritePropertyName("routing");
			JsonSerializer.Serialize(writer, RoutingValue, options);
		}

		if (VersionValue.HasValue)
		{
			writer.WritePropertyName("version");
			writer.WriteNumberValue(VersionValue.Value);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class PercolateQueryDescriptor : SerializableDescriptor<PercolateQueryDescriptor>
{
	internal PercolateQueryDescriptor(Action<PercolateQueryDescriptor> configure) => configure.Invoke(this);

	public PercolateQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private object? DocumentValue { get; set; }
	private ICollection<object>? DocumentsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Id? IdValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; }
	private string? NameValue { get; set; }
	private string? PreferenceValue { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Routing? RoutingValue { get; set; }
	private long? VersionValue { get; set; }

	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The source of the document being percolated.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Document(object? document)
	{
		DocumentValue = document;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An array of sources of the documents being percolated.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Documents(ICollection<object>? documents)
	{
		DocumentsValue = documents;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field that holds the indexed queries. The field must use the <c>percolator</c> mapping type.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The ID of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Id(Elastic.Clients.Elasticsearch.Id? id)
	{
		IdValue = id;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The index of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The suffix used for the <c>_percolator_document_slot</c> field when multiple <c>percolate</c> queries are specified.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Name(string? name)
	{
		NameValue = name;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Preference used to fetch document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Preference(string? preference)
	{
		PreferenceValue = preference;
		return Self;
	}

	public PercolateQueryDescriptor QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Routing used to fetch document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Routing(Elastic.Clients.Elasticsearch.Routing? routing)
	{
		RoutingValue = routing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The expected version of a stored document to percolate.
	/// </para>
	/// </summary>
	public PercolateQueryDescriptor Version(long? version)
	{
		VersionValue = version;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (DocumentValue is not null)
		{
			writer.WritePropertyName("document");
			JsonSerializer.Serialize(writer, DocumentValue, options);
		}

		if (DocumentsValue is not null)
		{
			writer.WritePropertyName("documents");
			JsonSerializer.Serialize(writer, DocumentsValue, options);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (IdValue is not null)
		{
			writer.WritePropertyName("id");
			JsonSerializer.Serialize(writer, IdValue, options);
		}

		if (IndexValue is not null)
		{
			writer.WritePropertyName("index");
			JsonSerializer.Serialize(writer, IndexValue, options);
		}

		if (!string.IsNullOrEmpty(NameValue))
		{
			writer.WritePropertyName("name");
			writer.WriteStringValue(NameValue);
		}

		if (!string.IsNullOrEmpty(PreferenceValue))
		{
			writer.WritePropertyName("preference");
			writer.WriteStringValue(PreferenceValue);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (RoutingValue is not null)
		{
			writer.WritePropertyName("routing");
			JsonSerializer.Serialize(writer, RoutingValue, options);
		}

		if (VersionValue.HasValue)
		{
			writer.WritePropertyName("version");
			writer.WriteNumberValue(VersionValue.Value);
		}

		writer.WriteEndObject();
	}
}